package com.mxx.common.utils;

import org.bson.Document;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * @Author itzgyw
 * @Date 2020-02-12
 * @Time 12:52
 * @Description:
 */
public final class BsonUtil {


    public static void display(Document document, String... columns) {
        for (int index = 0; index < columns.length; index++) {
            document.append(columns[index], 1);
        }
    }

    public static void display(Document document, Class classes) {
        Field[] fields = classes.getDeclaredFields();
        for (int index = 0; index < fields.length; index++) {
            Field field = fields[index];
            if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) {
                continue;
            }
            document.append(field.getName(), 1);
        }
    }

    public static void noDisplay(Document document, String... columns) {
        for (int index = 0; index < columns.length; index++) {
            document.append(columns[index], 0);
        }
    }

    public static void noDisplay(Document document, Class classes) {
        Field[] fields = classes.getDeclaredFields();
        for (int index = 0; index < fields.length; index++) {
            Field field = fields[index];
            if (Modifier.isFinal(field.getModifiers()) || Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers())) {
                continue;
            }
            document.append(field.getName(), 0);
        }
    }

}
